// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'


import './assets/reset.css'

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'

import VueResource from 'vue-resource'

import '../static/ueditor/ueditor.config.js'
import '../static/ueditor/ueditor.all.min.js'
import '../static/ueditor/lang/zh-cn/zh-cn.js'
import '../static/ueditor/ueditor.parse.min.js'
import global_ from './components/global_conf.vue'
Vue.prototype.GLOBAL = global_

import BaiduMap from 'vue-baidu-map'
Vue.use(BaiduMap, {
  ak: '75E2ba07d43ab7f994770ccb4a3d87d3'
})

Vue.use(VueResource)
Vue.use(ElementUI)
Vue.use(VueAwesomeSwiper)

Vue.config.productionTip = false;


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  render: h => h(App)
})

/*在路由跳转前进行登录判断*/
router.beforeEach((to, from, next) => {
  if (to.matched.some(record => record.meta.requireAuth)){  // 判断该路由是否需要登录权限
    if (JSON.parse(localStorage.getItem("user")) != null) {  // 判断当前的token是否存在
      next();
    }else {
    	if(confirm("您需要登录后才可进入会员中心，是否需要现在登录？")){
    		next({
    		  path: '/ymRegister',
    		  query: {redirect: to.fullPath}  // 将跳转的路由path作为参数，登录成功后跳转到该路由
    		});    		
    	}
    }
  }else {
    next();
  }
});
